package com.ngc.mall.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ngc.mall.common.configure.mybatisPlus.BaseServiceImpl;
import com.ngc.mall.domain.GridCategoryDomain;
import com.ngc.mall.dto.GridCategoryDTO;
import com.ngc.mall.mapper.GridCategoryMapper;
import com.ngc.mall.service.IGridCategoryService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GridCategoryServiceImpl extends BaseServiceImpl<GridCategoryMapper, GridCategoryDomain> implements IGridCategoryService {

    @Override
    public Long createGridCategory(GridCategoryDTO dto){
        return super.create(GridCategoryDomain.builder().categoryId(dto.getCategoryId()).img(dto.getImg()).name(dto.getName()).sort(dto.getSort()).type(dto.getType()).path(dto.getPath()).activityId(dto.getActivityId()).isEnabled(dto.getIsEnabled()).build());
    }

    @Override
    public List<GridCategoryDomain> selectAll(){
        return super.list();
    }

    @Override
    public GridCategoryDomain getDetailById(Long id) {
        return super.getById(id);
    }

    @Override
    public Boolean updateGridCategory(GridCategoryDTO dto,Long id){
        return super.update(Wrappers.<GridCategoryDomain>lambdaUpdate().eq(GridCategoryDomain::getId,id).set(GridCategoryDomain::getName,dto.getName()).set(GridCategoryDomain::getImg,dto.getImg()).set(GridCategoryDomain::getType,dto.getType()).set(GridCategoryDomain::getSort,dto.getSort()).set(GridCategoryDomain::getPath,dto.getPath()).set(GridCategoryDomain::getActivityId,dto.getActivityId()).set(GridCategoryDomain::getIsEnabled,dto.getIsEnabled()));
    }

    @Override
    public Boolean updateStatusById(Long id, Boolean status) {
        return super.update(Wrappers.<GridCategoryDomain>lambdaUpdate().eq(GridCategoryDomain::getId,id).set(GridCategoryDomain::getIsEnabled,status));
    }

    @Override
    public Boolean deleteById(Long id) {
        return super.removeById(id);
    }
}
